//
//  ViewController.swift
//  SHStarRatingView
//
//  Created by shihu on 2021/11/3.
//

import UIKit

class ViewController: UIViewController {
    
    let width: Int = 30 // 星星的宽、高
    
    private lazy var starRatingView: SHStarRatingView = {
        let temp = SHStarRatingView(frame: CGRect(x: 10, y: 200, width: width * 5 + 5 , height: width))
        temp.setBottomImageName("icon_star_gray", topIconStr: "icon_star_yellow", starCount: 5)
        temp.allowIncompleteStar = true  // 是否允许, 整颗星
        temp.allowAnimation = true  // 动画
        temp.allowProhibitManuallyStar = false // 禁止手动评分
        temp.scorePercent = 3.6 / 5 // 默认评分  (0 - 1)
        temp.delegate = self
        temp.backgroundColor = .yellow
        return temp
    }()
    
    lazy var nuberLabel: UILabel = { // 评分数值
        let temp: UILabel = UILabel(frame: CGRect(x: 0, y: 260, width: 300, height: 20))
        temp.text = "3.60"
        temp.textAlignment = .center
        temp.textColor = .red
        
        temp.backgroundColor = .yellow
        return temp
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubview(self.starRatingView)  //添加....五角星...
        self.view.addSubview(self.nuberLabel)      //添加....五角星数值...
    }
    
}

// MARK: - Private method

extension ViewController: SHStarRatingViewDelegate {
    
    func starRateView(_ starRateView: SHStarRatingView, currentScorePercent: CGFloat) {
        print("newScorePercent======\(currentScorePercent * 5)")
        self.nuberLabel.text = "\(currentScorePercent * 5)"
    }
    
}

